/**
 * Created by zhangb on 2015/10/10.
 */
//添加监听事件
var addBtn = document.getElementById('addBtn');
function addcallback()
{
    alert('addEventListener');
}
addBtn.addEventListener('click',addcallback);
//移除监听事件
var removeBtn = document.getElementById('removeBtn');
function removecallback()
{
    alert('removeEventListener');
    removeBtn.removeEventListener('click',removecallback);
}
removeBtn.addEventListener('click',removecallback);

var context = document.getElementById('context');
var user =
{
    firstName:"Context",
    greeting:function()
    {
        alert('My name is ' + this.firstName);
    }
}
function callback()
{
    console.log(this);
}
//context.addEventListener('click',user.greeting);  this指向的是context，而不是user。
//TODO 方法1
//context.addEventListener('click',function(){user.greeting()});
//TODO 方法2
user.greeting = user.greeting.bind(user);
context.addEventListener('click',user.greeting);
